package com.carb.controller.member;

import com.carb.context.UserContext;
import com.carb.enums.MemberLevel;
import com.carb.result.Result;
import com.carb.service.IMemberService;
import com.carb.vo.MemberVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 会员管理 前端控制器
 * </p>
 *
 * @author XuChaoyang
 * @since 2025-01-18
 */
@RestController("memberMemberController")
@RequestMapping("/member/member")
@Tag(name = "会员管理相关接口")
@Slf4j
public class MemberController {

    @Resource
    private IMemberService memberService;

    /**
     * 获取当前登录会员信息
     * @return 查询结果
     */
    @GetMapping
    @Operation(summary = "获取当前登录会员信息")
    public Result<MemberVO> getCurrentMember() {
        Long userId = UserContext.getUserId();
        log.info("获取当前登录会员信息：{}", userId);
        MemberVO memberVO = memberService.getMemberByUserId(userId);
        log.info("根据会员id查询会员信息成功！");
        return Result.success(memberVO);
    }

    /**
     * 当前登录会员余额充值
     * @param amount 充值金额（整数，单位为元）
     */
    @PostMapping("/recharge/{amount}")
    @Operation(summary = "当前登录会员余额充值")
    public Result<String> rechargeBalanceForMember(@PathVariable @Parameter(description = "充值金额") Integer amount) {
        log.info("当前登录会员余额充值，充值金额：{}", amount);
        memberService.rechargeBalanceForMember(amount);
        log.info("当前登录会员余额充值成功！");
        return Result.success();
    }

    /**
     * 当前登录会员升级
     * @param memberLevel 会员等级
     */
    @PostMapping("/upgrade/{memberLevel}")
    @Operation(summary = "当前登录会员升级")
    public Result<String> upgradeCurrentMember(@PathVariable @Parameter(description = "会员等级") MemberLevel memberLevel) {
        log.info("当前登录会员升级");
        memberService.upgradeCurrentMember(memberLevel);
        return Result.success();
    }

}
